package com.wuyou.mid;

import java.util.*;

/**
 * @Description
 * @Author 无忧
 * @Date 2023/10/11 21:36
 */
public class TopStudents {

    public static void main(String[] args) {
        String[] positive_feedback = {"smart","brilliant","studious"};
        String[] negative_feedback = {"not"};
        String[] report = {"this student is not studious","the student is smart"};
        int[] student_id = {1,2};
        Integer k = 2;
        System.out.println(topStudents(positive_feedback, negative_feedback, report, student_id, k));
    }

    public static List<Integer> topStudents(String[] positive_feedback, String[] negative_feedback, String[] report, int[] student_id, int k) {
        Map<String, Integer> pMap = new HashMap<String, Integer>();
        Map<String, Integer> nMap = new HashMap<String, Integer>();
        for (int i = 0; i < negative_feedback.length; i++) {
            nMap.put(negative_feedback[i], i);
        }
        for (int i = 0; i < positive_feedback.length; i++) {
            pMap.put(positive_feedback[i], i);
        }
        List<User> temp = new ArrayList<>();
        for (int i = 0; i < student_id.length; i++) {
            String[] s = report[i].split(" ");
            User user = new User();
            user.setId(student_id[i]);
            int score = 0;
            for (int j = 0; j < s.length; j++) {
                if (pMap.get(s[j]) != null) {
                    score += 3;
                }else if (nMap.get(s[j]) != null) {
                    score -= 1;
                }
            }
            user.setScore(score);
            temp.add(user);
        }
        temp.sort(new Comparator<User>() {
            @Override
            public int compare(User o1, User o2) {
                if (o1.getScore() == o2.getScore()) {
                    return o1.getId() - o2.getId();
                }
                return o2.getScore() - o1.getScore();
            }
        });
        List<Integer> ans = new ArrayList<>(k);
        if (temp.size() >= k) {
            for (int i = 0; i < k; i++) {
                ans.add(temp.get(i).getId());
            }
        }
        return ans;
    }

    static class User {
        Integer id;
        Integer score;

        public void setId(int id) {
            this.id = id;
        }

        public int getId() {
            return this.id;
        }

        public Integer getScore() {
            return this.score;
        }

        public void setScore(int score) {
            this.score = score;
        }
    }
}
